package controllers

import (
	"fmt"
	"github.com/astaxie/beego"
	"html/template"
	"xianzhi/service"
)

type IndexController struct {
	BaseController
}

func (c *IndexController) Index() {
	userId := c.GetSession("userId")
	key := fmt.Sprintf("selected_%d", userId)
	c.SetSession(key, "")

	p := map[string]interface{}{}
	p["userId"] = userId
	orderCount, _ := service.GetOrderList(p)
	if orderCount > 0 {
		c.Redirect(beego.URLFor("controllers.SchoolController.Index"), 302)
		return
	}

	p = map[string]interface{}{}
	p["status"] = 1
	_, setMealList := service.GetSetMealList(p)
	c.Data["setMealList"] = setMealList

	c.Data["xsrfdata"] = template.HTML(c.XSRFFormHTML())
	c.TplName = "index.html"
}
